package DamonThread;

class damon implements Runnable{

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"线程正在运行！");
    }
}

public class damonThread {
    public static void main(String[] args) {

        // 判断是否为后台进程
        System.out.println("main线程是后台线程吗"+Thread.currentThread().isDaemon());

        // 创建接口实现类的实例化对象
        damon d = new damon();
        // 调用Thread的含参构造方法创建线程
        Thread thread = new Thread(d,"后台线程");
        System.out.println("thread线程吗，默认是后台线程吗？"+thread.isDaemon());
        // 将thread线程对象转换为后台线程
        thread.setDaemon(true);
        thread.start();

        // 模拟主线程main的执行
        for(int i=0;i<5;i++){
            System.out.println(i);
        }

    }
}
